
#include "DHT.h"
#include <LiquidCrystal.h>//声明调用库

#define DHTPIN 7     // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11   // DHT 11
DHT dht(DHTPIN, DHTTYPE);

const int rs=12,en=11,d4=5,d5=4,d6=3,d7=2;//对应引脚
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);//创建一个名为lcd的实例（对象），这里是4线法d4~d7
void setup() {
  Serial.begin(9600);
  Serial.println(F("DHTxx test!"));
  dht.begin();

  lcd.begin(16,2);//初始化LCD的宽度和高度,设置16列2行
  lcd.print("Hi,Lei Ge!");//向LCD输出内容
}
 
void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print(F("Humidity: "));
  Serial.print(h);
  Serial.print(F("%  Temperature: "));
  Serial.print(t);
  Serial.print(F("°C "));
  Serial.print(f);
  Serial.print(F("°F  Heat index: "));
  Serial.print(hic);
  Serial.print(F("°C "));
  Serial.print(hif);
  Serial.println(F("°F"));

  //lcd.setCursor(0,1);//把光标设置在0列1行(第2行开头)上
  //lcd.print(millis()/1000);//把系统运行的时间打到屏幕上

  lcd.setCursor(0,0);
  lcd.print(F("Humidity: "));
  lcd.print(h);
  lcd.print(F("%"));
  lcd.setCursor(0,1);
  lcd.print(F("Temp:"));
  lcd.print(t);
  lcd.print(F("'C "));
}